﻿using System.Windows;
using System.Windows.Controls;

using GalaSoft.MvvmLight.Messaging;

using Rio.Framework.Pages;
using Rio.Manager.Application.Utils;

namespace Rio.Manager.Application.Views
{
    public partial class ManageWorkflowModelTabView : UserControl
    {
        #region Constructors

        public ManageWorkflowModelTabView()
        {
            InitializeComponent();

            Unloaded += (s, e) =>
            {
                Messenger.Default.Unregister<RioDialogMessage>(this, ShowDialog);
            };

            Messenger.Default.Register<RioDialogMessage>(this, ShowDialog);
        }

        #endregion Constructors

        #region Methods

        private void ShowDialog(RioDialogMessage msg)
        {
            MessageBoxChildWindow confirmWindow = new MessageBoxChildWindow(msg.Caption, msg.Content, msg.Button, msg.Icon);

            confirmWindow.Closed += (sender, e) =>
            {
                if (confirmWindow.DialogResult == true)
                {
                    msg.ProcessCallback(MessageBoxResult.Yes);
                }
                else
                {
                    msg.ProcessCallback(MessageBoxResult.No);
                }
            };

            confirmWindow.Show();
        }

        #endregion Methods
    }
}